package com.tarena.lbs.message.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.BasePageQuery;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.message.pojo.param.TimingMsgParam;
import com.tarena.lbs.message.pojo.vo.TimingMsgTemplateVO;
import com.tarena.lbs.message.service.TimingMsgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "定时消息接口")
@Slf4j
@RestController
@RequiredArgsConstructor
public class TimingMsgController {
    private final TimingMsgService timingMsgService;
    @Operation(summary = "查询所有定时消息模板")
    @PostMapping("/admin/message/timingMsgTemplate/selectAll")
    private Result<PageResult<TimingMsgTemplateVO>> selectAll(BasePageQuery query)
            throws BusinessException{
        log.debug("查询所有定时消息模板,消息分页参数: query={}",query);
        PageResult<TimingMsgTemplateVO> pageResult = timingMsgService.selectAll(query);
        log.debug("查询所有定时消息模板成功,出参:{}",pageResult.getObjects());
        return new Result<>(pageResult);
    }
    @Operation(summary = "新增定时消息模板")
    @PostMapping("/admin/message/timingMsgTemplate/insert")
    public Result<Void> addTemplate(TimingMsgParam param)
            throws BusinessException {
        log.debug("新增定时消息模板,入参:{}",param);
        timingMsgService.saveTemplate(param);
        log.debug("新增定时消息模板成功");
        return Result.success();
    }
    @Operation(summary = "修改定时消息模板")
    @PostMapping("/admin/message/timingMsgTemplate/updateById")
    public Result<Void> updateTemplate(TimingMsgParam param)
            throws BusinessException {
        log.debug("修改定时消息模板,入参:{}",param);
        timingMsgService.saveTemplate(param);
        log.debug("修改定时消息模板成功");
        return Result.success();
    }
    @Operation(summary = "删除定时消息模板")
    @PostMapping("/admin/message/timingMsgTemplate/deleteById")
    public Result<Void> deleteTemplate(Integer id)
            throws BusinessException {
        log.debug("删除定时消息模板,入参消息id:{}",id);
        timingMsgService.deleteTemplate(id);
        log.debug("删除定时消息模板成功");
        return Result.success();
    }
}
